package com.netty.exmple.zerocopy;


import java.io.FileInputStream;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class NewIOClient {
    public static void main(String[] args) throws Exception{
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost", 8888));
        socketChannel.configureBlocking(true);
        String fileName = "D:\\softPackage\\ideaIU-2019.1.3.exe";
        FileChannel fileChannel = new FileInputStream(fileName).getChannel();
        long startTime = System.currentTimeMillis();
        long transferCount = fileChannel.transferTo(0L, fileChannel.size(), socketChannel);
        System.out.println("发送的总字节数组：" + transferCount + "，耗时：" + (System.currentTimeMillis() - startTime));
        fileChannel.close();
    }
}
